using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Skillbloodrage211 : SkillBasic
{
    public float CD;
    private float CDtime;
    PlayerAttack attack;
    PlayerBasic player;
    ParticleSystem particle;
    public float damageratio;
    public float skilltime;
    public float Recoveryratio;
    public float healthlossingratio;
    public float speedratio;
    bool isskilling;
    int skilltimes;
    // Start is called before the first frame update
    void Start()
    {
        attack = GameObject.FindWithTag("Attack").GetComponent<PlayerAttack>();
        player = GetComponentInParent<PlayerBasic>();
        particle = GetComponentInChildren<ParticleSystem>();
        particle.Stop();
        BloodrageCD.CD = CD;
        BloodrageCD.CDCurrent = 0;
        isskilling = false;
        skilltimes = 0;
    }
    void skillend()
    {
        attack.truedamage -= damageratio * attack.basicdamage;
        player.Runspeed -= player.basicrunspeed * speedratio;
        particle.Stop();
        isskilling = false;
        player.healthrecoveryratio -= Recoveryratio;
    }
    public IEnumerator Skilling()
    {
        yield return new WaitForSeconds(skilltime);
        skillend();

    }
    void Skill()
    {
        isskilling = true; 
        attack.truedamage += damageratio * attack.basicdamage;
        player.Runspeed += player.basicrunspeed * speedratio;
        particle.Play();
        player.healthrecoveryratio += Recoveryratio;
        skilltimes++;
        if (skilltimes == 3)
        {
            CDtime = 1000000f;
            CD = 1000000f;
        }
        StartCoroutine(Skilling());
    }
    void Update()
    {
        
        if (CDtime > 0)
        {
            CDtime -= Time.deltaTime;
            BloodrageCD.CDCurrent = CDtime;
        }
        if (Input.GetKeyDown(KeyCode) && Time.timeScale > 0)
        {
            if (CDtime <= 0 && player.movable)
            {
                Skill();
                CDtime = CD;
            }
        }
        if (isskilling&& Time.timeScale>0)
        {
            player.Recovery(-skilltimes*healthlossingratio * player.health);
        }
    }
}
